package com.rongc.client.freight.business.mine.view.activity;

import android.text.Html;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.TextView;

import com.flyco.dialog.listener.OnOperItemClickL;
import com.flyco.dialog.widget.NormalListDialog;
import com.rongc.client.core.exception.RegexException;
import com.rongc.client.core.utils.ActivityUtils;
import com.rongc.client.core.utils.RegexUtil;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseActivity;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by ccqx on 2017/7/17.
 */

public class TixianActivity extends BaseActivity implements View.OnClickListener{
    @Bind(R.id.tv_bank)
    TextView mTvBank;
    @Bind(R.id.et_balance)
    EditText mEtBalance;
    @Bind(R.id.tv_balance_tip)
    TextView mTvBalanceTip;

    NormalListDialog dialog ;

    @OnClick({R.id.tv_bank,R.id.btn_submit,R.id.tv_all})
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_bank:
                dialog.show();
                break;
            case R.id.btn_submit:
                try{
                    prepare();
//                    RequestManager.getInstance().call(new RegisterCodeApi(new RegisterCodeApi.RegisterCodeParams(mEtPhone.getText().toString()),
//                            respCodeListener, errorListener));
                }catch (RegexException e){
                    ActivityUtils.toast(e.getMessage());
                }
                break;
            case R.id.tv_all:
                mEtBalance.setText("98.5");
                break;
        }
    }

    void prepare() throws RegexException {
        if (!RegexUtil.checkNotNull(mEtBalance.getText().toString())) {
            throw new RegexException("请输入提现余额");
        } else if (!RegexUtil.checkNotNull(mTvBank.getText().toString())) {
            throw new RegexException("请输入提现银行");
        }
    }

    String[] abank = new String[]{"农业银行卡（5689）","农业银行卡（5689）","添加银行卡提现"};
    @Override
    public void initView() {
        initToolbar(R.string.tixian_title);

        mTvBalanceTip.setText(Html.fromHtml(String.format(getResources().getString(R.string.tixian_balance_tip),"98.5")));
        dialog = new NormalListDialog(this,abank);
        dialog.title("选择银行卡")
                .layoutAnimation(null)
                .setOnOperItemClickL(new OnOperItemClickL() {
                    @Override
                    public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
                        if(position == abank.length - 1){

                        }else{
                            dialog.cancel();
                            mTvBank.setText(abank[position]);
                        }
                    }
                });

    }


    @Override
    public int getLayoutId() {
        return R.layout.activity_tixian;
    }
}
